package com.example.mynote.activity;

import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.mynote.R;
import com.example.mynote.base.BaseActivity;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends BaseActivity {

    private com.youth.banner.Banner banner;
    private List<Integer> icon = new ArrayList<>();
    private android.widget.Button guiBtn;

    @Override
    protected int initLayout() {
        return R.layout.activity_guide;
    }

    @Override
    protected void initView() {

        banner = (Banner) findViewById(R.id.banner);
        guiBtn = (Button) findViewById(R.id.gui_btn);
    }

    @Override
    protected void initData() {

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        icon.add(R.mipmap.a1);
        icon.add(R.mipmap.a2);
        icon.add(R.mipmap.a3);

        banner.setAdapter(new BannerImageAdapter<Integer>(icon) {
            @Override
            public void onBindView(BannerImageHolder bannerImageHolder, Integer integer, int i, int i1) {
                Glide.with(GuideActivity.this).load(integer).into(bannerImageHolder.imageView);
                bannerImageHolder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            }
        }, false).setIndicator(new CircleIndicator(GuideActivity.this)).start();


        banner.addOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                if (i == icon.size() - 1) {
                    guiBtn.setVisibility(View.VISIBLE);
                    AlphaAnimation animation = new AlphaAnimation(0.1f, 1f);
                    animation.setDuration(1000);
                    guiBtn.startAnimation(animation);
                } else {
                    guiBtn.setVisibility(View.GONE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

        guiBtn.setOnClickListener(v -> {
            intentTo(LoginActivity.class);
            finish();
        });
    }
}